package sicnu.cs.ich.ich.ranking.mq;

import org.apache.rocketmq.common.message.MessageExt;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author CaiKe
 * @date 2021/12/2 16:56
 */
public abstract class Father {

    protected void consumeMsg(MessageExt message, String tag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//        final Class<? extends AbstractRocketConsumer> aClass = this.getClass();
//        System.out.println("===============");
//        System.out.println(aClass.getName());
//        for (Method amethod : aClass.getDeclaredMethods()) {
//            System.out.println(amethod.getName() + " :: " + Arrays.toString(amethod.getParameterTypes()));
//        }
//        System.out.println("==================");
        Method method;
        try {
            method = this.getClass().getDeclaredMethod(tag, MessageExt.class);
        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
            throw new NoSuchMethodException("无该方法：" + tag + "，" + e.getMessage());
        }
        method.invoke(this, message);
    }

}